//package com.csthink.web.infrastructure.security.authentication.filter;
//
//import com.csthink.common.infrastructure.enums.ErrorEnum;
//import com.csthink.common.infrastructure.util.AssertUtil;
//import com.csthink.common.infrastructure.util.JwtUtils;
//import com.csthink.mysql.entity.User;
//import com.csthink.web.application.service.UserService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.stereotype.Component;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.annotation.Resource;
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.Collections;
//
///**
// * 基础版
// * @author <a href="mailto:security.2009@live.cn">Mars</a>
// * @since 2023-09-12
// */
//@Slf4j
//@Component
//public class LoginFilter extends OncePerRequestFilter {
//
//    @Resource
//    private UserService userService;
//
//    @Resource
//    private JwtUtils jwtUtils;
//
//    @Override
//    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//        log.info("\n {} - {}", request.getMethod(), request.getRequestURL().toString());
//
//
////        String authorizationHeader = request.getHeader(AUTHORIZATION);
////        if (StringUtils.isBlank(authorizationHeader) || !authorizationHeader.startsWith(AUTHORIZATION_BEARER)) {
////            throw new BaseException(ErrorEnum.JWT_TOKEN_INVALID);
////        }
////
////        String token = authorizationHeader.substring(AUTHORIZATION_BEARER.length());
////        Claims claims = jwtUtils.parseJwt(token);
//
//        User user = userService.loadByUsername("222");
//        AssertUtil.notNull(user, ErrorEnum.USER_NOT_FOUND);
//        Authentication authentication = new UsernamePasswordAuthenticationToken(user, "111", Collections.emptyList());
//        SecurityContextHolder.getContext().setAuthentication(authentication);
//        filterChain.doFilter(request, response);
//    }
//}
